#include"head.h"
#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#define NUM 101
#define CH '='
#define Long 1024
void fun(double now,double dct)
{
    int k=(int)(now*100/dct);
    char ret[NUM];
    memset(ret,0,NUM);
    int  i=0;
    char ch[]="|/-\\";
    static int count=0;
    while(k--)
    {
        ret[i++]=CH;
    }
    double v=now/dct;
    printf("[%-100s][%-5.2f%%][%c]\r",ret,v*100,ch[count%3]);
    fflush(stdout);
    count++;
}
void download()
{
    int count=0;
    srand((unsigned int)time(NULL));
    while(count<=Long)
    {
        fun(count,Long);
        int tm=4000+rand()%(40000-4000+1);
        int tn=10+rand()%(100-10+1);
        usleep(rand()%2?tm:tn);
        count++;
    }
    printf("\n");
}
